package fr.montreuil.wargame.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity(name="user")
public class User {
	
	@Id
	@GeneratedValue
	private Long id;
	
	@NotEmpty
	private String firstName;
	@NotEmpty
	private String lastName;
	
	@Column(unique=true)
	@NotEmpty
	@Size(min=5, max=20)
	private String username;
	
	@NotEmpty
	@Size(min=5)
	private String password;
	
	@OneToOne(mappedBy="user", cascade={CascadeType.ALL})
	private Role role;
	
	private int lvl;
	private int exp;
	private int expMax;
	
	@OneToOne(mappedBy="user", cascade={CascadeType.ALL})
	private Resources resources;
	
	@OneToMany(fetch=FetchType.LAZY)
	private List<Batiment> batiments;
	@OneToMany(fetch=FetchType.LAZY)
	private List<Technologie> technologies;
	
	/**********************************
	 ***	Méthodes
	 **********************************/

	public void addExp(int exp){
		if((this.exp + exp)>= this.expMax){
			this.lvl++;
			this.expMax = ((this.lvl * 2) * 100) + (this.lvl * 5);
		}
		
		this.exp = this.exp + exp;
	}
	
	/**********************************
	 ***	Getteurs / Setteurs
	 **********************************/

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public int getLvl() {
		return lvl;
	}

	public void setLvl(int lvl) {
		this.lvl = lvl;
	}

	public int getExp() {
		return exp;
	}

	public void setExp(int exp) {
		this.exp = exp;
	}

	public int getExpMax() {
		return expMax;
	}

	public void setExpMax(int expMax) {
		this.expMax = expMax;
	}

	public Resources getResources() {
		return resources;
	}

	public void setResources(Resources resources) {
		this.resources = resources;
	}

	public List<Batiment> getBatiments() {
		return batiments;
	}

	public void setBatiments(List<Batiment> batiments) {
		this.batiments = batiments;
	}

	public List<Technologie> getTechnologies() {
		return technologies;
	}

	public void setTechnologies(List<Technologie> technologies) {
		this.technologies = technologies;
	}
}
